<?php $this->headStyle()->captureStart() ?>
<?php $this->headStyle()->captureEnd() ?>

<?php $this->headScript()->captureStart() ?>
$(document).ready(function() {
    
    var optionsBase = {
        "callback": function( sValue, y ) {

        },
        "cssclass"      : 'jeditable',
        "method"        : 'POST',
        "event"         : 'dblclick',
        "tooltip"       : 'Click to edit',
        "placeholder"   : '&nbsp;',
        "submit"        : 'Ok',
        "cancel"        : 'Cancel',
        "onblur"        : 'ignore',
        "submitdata"   : function ( value, settings ) {
            var _roleId   = $(this).attr("data-roleId").trim();
            var _accessId = $(this).attr("data-accessId").trim();
            
            return {
                "roleId"   : _roleId,
                "accessId" : _accessId,
            };
        },
        "height"        : null,
        "width"            : null,
    }
    var _jeditableSubmitUrl = '<?php echo $this->url(array('module'=>'admin', 'controller'=>'user-acl', 'action'=>'save-role-access-for-jeditable')); ?>';
    var _jeditableLoadUrl   = '<?php echo $this->url(array('module'=>'admin', 'controller'=>'user-acl', 'action'=>'get-role-access-for-jeditable')); ?>';

    var optionsExtend = {
        "type"        : "select",
        "loaddata": function ( value, settings ) {
            var _roleId   = $(this).attr("data-roleId").trim();
            var _accessId = $(this).attr("data-accessId").trim();

            return {
                "roleId"   : _roleId,
                "accessId" : _accessId,
            };
        },
        "loadtype": 'POST',
        "loadurl" : _jeditableLoadUrl,
    }
    var options = $.extend({}, optionsBase, optionsExtend);
    $('div.jeditable-box').editable( _jeditableSubmitUrl, options);

});
<?php $this->headScript()->captureEnd() ?>


<?php if(!$this->showType):?>
<?php 
$_tableFirstThWidth = "160";
$_tableOthorThWidth = "120";
$_tableWidth = $_tableFirstThWidth;
if(is_array($this->roleFamilyArray)){
    $num = count($this->roleFamilyArray);
    $_tableWidth += $num*$_tableOthorThWidth;
}
?>

<div class="clearfix">
    <table cellpadding="0" cellspacing="0" border="0" width="<?php echo $_tableWidth;?>">
    <caption><em><?php echo $this->roleRow['roleName'];?></em></caption>
    <thead>
    <tr>
        <th width="<?php echo $_tableFirstThWidth;?>"></th>

        <?php if(is_array($this->roleFamilyArray)):?>
        <?php foreach ($this->roleFamilyArray as $key=>$roleRow):?>
        <th width="<?php echo $_tableOthorThWidth;?>">
            <?php echo $roleRow['roleName'];?>
        </th> 
        <?php endforeach;?>
        <?php endif;?>
    </tr>
    </thead>
    <?php foreach($this->accessGroupes as $accessId=>$accesses):?>
    <?php if(is_array($accesses)):?>
    <?php foreach ($accesses as $key1=>$accessRow):?>
    <tr> 
        <td>
            
        <?php if($accessRow['parentId']):?>
            &nbsp;|--
        <?php endif;?>

        <?php if($accessRow['parentId']):?>
            <?php echo $accessRow['accessName'];?>
        <?php else:?>
            <strong><?php echo $accessRow['accessName'];?></strong>
        <?php endif;?>
            
        </td>
        <?php if(is_array($accessRow['control'])):?>
        <?php foreach ($accessRow['control'] as $key2=>$controlRow):?>
        <td>
            <div class="access jeditable-box" data-roleId="<?php echo $controlRow['roleId'];?>" data-accessId="<?php echo $controlRow['accessId'];?>">
                <?php echo $controlRow['controlName'];?>
            </div>
        </td>
        <?php endforeach;?>
        <?php endif;?>
    </tr> 
    <?php endforeach;?>
    <?php endif;?>
    <?php endforeach;?>
    </table>
</div>


<?php else:?>
<?php 
$_tableFirstThWidth = "120";
$_tableOthorThWidth = "120";
$_tableWidth = $_tableFirstThWidth;
if(is_array($this->accessAllArray)){
    $num = count($this->accessAllArray);
    $_tableWidth += $num*$_tableOthorThWidth;
}
?>
<div class="marginTop10">
    <table cellpadding="0" cellspacing="0" border="1" width="<?php echo $_tableWidth;?>" class="display tableA" id="dataTableA"> 
        <thead>
            <tr>
                <th width="<?php echo $_tableFirstThWidth;?>"><?php echo $this->translate("Rold id");?></th>
                <th width="<?php echo $_tableFirstThWidth;?>"><?php echo $this->translate("Rold name");?></th>
                
                <?php if(is_array($this->accessAllArray)):?>
                <?php foreach ($this->accessAllArray as $key=>$accessRow):?>
                <th width="<?php echo $_tableOthorThWidth;?>">
                    <?php echo $accessRow['accessName'];?>
                </th> 
                <?php endforeach;?>
                <?php endif;?>
            </tr>
        </thead>
        <tbody> 
              <?php if(is_array($this->roleFamilyArray)):?>
            <?php foreach ($this->roleFamilyArray as $key1=>$roleRow):?>
            <tr> 
                <td>
                    <?php echo $roleRow['id'];?>
                </td>
                <td>
                    <?php echo $roleRow['roleName'];?>
                </td>
                
                <?php if(is_array($roleRow['control'])):?>
                <?php foreach ($roleRow['control'] as $key2=>$control):?>
                <td>
                    <div class="access jeditable-box" roleId="<?php echo $control['roleId'];?>" accessId="<?php echo $control['accessId'];?>">
                        <?php echo $control['controlName'];?>
                    </div>
                </td>
                <?php endforeach;?>
                <?php endif;?>
            </tr> 
            <?php endforeach;?>
            <?php endif;?>
         </tbody>
    </table>
</div>
<?php endif;?>
